package com.onedec.designer.service.impl;

import com.onedec.designer.entity.OnedecContract;
import com.onedec.designer.entity.OnedecContractExample;
import com.onedec.designer.entity.OnedecPlan;
import com.onedec.designer.entity.OnedecPlanExample;
import com.onedec.designer.mapper.OnedecContractMapper;
import com.onedec.designer.mapper.OnedecPlanMapper;
import com.onedec.designer.service.OnedecContractService;
import com.onedec.designer.service.OnedecPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class OnedecPlanServiceImpl implements OnedecPlanService {
    @Autowired
    private OnedecPlanMapper onedecPlanMapper;


    @Override
    public List<Map<String, Object>> selectByMap(Map<String, Object> map) {
        return onedecPlanMapper.selectByMap(map);
    }

    @Override
    public long accountnum() {
        return onedecPlanMapper.countByExample(null);
    }

    @Override
    public void deleteById(int id) {
        onedecPlanMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insertOne(OnedecPlan onedecPlan) {
        onedecPlanMapper.insertSelective(onedecPlan);
    }


    @Override
    public OnedecPlan selectById(int id) {
        return onedecPlanMapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(OnedecPlan onedecPlan) {
        onedecPlanMapper.updateByPrimaryKeySelective(onedecPlan);
    }

    @Override
    public void updateById(int id) {
        OnedecPlan onedecPlan = onedecPlanMapper.selectByPrimaryKey(id);
        onedecPlan.setPlanStatus("1");
        onedecPlanMapper.updateByPrimaryKeySelective(onedecPlan);
    }

    @Override
    public void rejectById(int id) {
        OnedecPlan onedecPlan = onedecPlanMapper.selectByPrimaryKey(id);
        onedecPlan.setPlanStatus("3");
        onedecPlanMapper.updateByPrimaryKeySelective(onedecPlan);
    }

    @Override
    public List<OnedecPlan> selectByProjectId(int id) {
        OnedecPlanExample onedecPlanExample = new OnedecPlanExample();

        OnedecPlanExample.Criteria or = onedecPlanExample.or();
        or.andPlanProjectIdEqualTo(id);

        return onedecPlanMapper.selectByExample(onedecPlanExample);
    }
}
